![]() |
BlueSpray - Help
©
SchoonerTurtles, Inc. 2012-2015 |
|||||||||
|
|
||||||||||
|
Beyond the ManagersNow that you've done some scripting and used the high-level managers, we're going to go deeper into BlueSpray to access static functions within a large number of classes to give you more flexibility and performance in scripting. TutorialsThe tutorials below will introduce you to scripting in BlueSpray but if you are unfamiliar with programming in JavaScript we recommend starting with our Introduction to JavaScript. If you have not used JavaScript in a Java program we recommend rreviewing our Introduction to JavaScript in Java Applications. There is also a JavaScript Guide and JavaScript Reference available here. Below are a series of samples to get you started scripting in BlueSpray. We recommend following the samples closely to avoid errors and then move on to the learn more about the possibilities of scripting.
Data TypesJavaScript supports standard data types including; Integers, Doubles, Strings, Dates, and arrays of these types. BlueSpray also provides support for; Coordinates, Tables, Layers, Geometries, and Rasters. Coordinates are simply represented as arrays of X,Y or X,Y,Z double values and can be in two-dimensional arrays to represent arrays of coordinates. Tables contains rows and columns that can contain any of the primitive types. Layers contain a table for attribute data and may contain additional spatial data.Geometries represent simple geographic shapes including points, line strings, polygons, and collections. See the Geometries section for more information. Rasters contain grids of pixels and can be spatially referenced. One of the great features of BlueSpray is that many of the functions will take a variety of data types and will do just what you want. For instance, when you load a shapefile you can ask to load the file into a layer for points, geometries, or vectors with the same function. If the function does not handle a particular type of data it will return an error. If you follow the tutorials below you'll learn more about the data types available in BlueSpray. Note: Geometries are based on the OpenGIS Consortium (OGC) Simple Feature Specifiction and support for them is provided by the Java Topology Suite from Vivid Solutions, Inc. Loading GIS FilesLoading data from common GIS files formats can be done with one call to the ST.File.Manager class. This includes loading Shapefile format data and BlueSpray includes a set of sample Shapefiles from the National Atlas dataset including countries, water bodies, rivers, and others. If you copied the BlueSpray folder to the root of your "C" drive the files will be in "C:/BlueSpray/UsersGuide/Data" and the examples below should work without any changes. If you copied the folder somewhere else, you'll need to change the file paths to match. var TheLayer=new LayerGeometry();
var Abort=FileManager.LoadFromFile("C:/BlueSpray/UsersGuide/Data/countries.shp",TheLayer);
if (Abort==false) Scene_1.AddChild(TheLayer);
After the script runs you should see the countries of the world appear in the BlueSpray window. BlueSpray supports a number of different types of file formats for vector-based GIS data (see the User's Guide for more information on supported file formats). Unfortunately, there are some file extensions that are used for the same formats. When using BlueSpray as an application the user will see a dialog box appear if there is confusion over a file extension. The file manager will try to open the file but may fail if the file format does not match the file extension. You can specify the specific file format by creating a file handler for that file format and using it to load the file. This also allows access to informatiopn that is specific to the file. - Example of reading a JPEG file and accessing the date fields on the raster
BlueSpray uses standard Java exception handling for errors. You do not need to "catch" these errors in your JavaScripts as we will redirect the error to your output. You'll see the error and the stack trace for where the error occurred. There will be more ifnormatoin on this a little later. Saving GIS FilesYou can save files to many GIS file formats through one call to the FileManager.
If you write a file with the file manager that has an extension with muitple file formats, BlueSpray will simply select the most commonly used format for the file. If you wnat to get more control over the writting of files you'll need to create a specific file handler and then call the handler to write the file. This also allows yo to access additional settings for the file format. Below is an exmaple of setting the compression for a JPEG file: - Example of writting a JPEG file format and setting the compressoin Accessing Project DataType the following script and press run. println(TheProject.GetName()); var TheScene=TheProject.GetFirstContent(Scene.class); println(TheScene.GetName());
sdf
- var TheScene=GetContent("Scenes.Scene 1");
- TheScene.SetVisible(false);
Projecting Data##########################################################################
# Script to project data to the GoogleMaps projection and back again
# Date: 4/12/2016
# Author: Jim Graham
##########################################################################
# Setup the gateway to BlueSpray (remember that BlueSpray must be running)
from py4j.java_gateway import JavaGateway
gateway = JavaGateway(auto_field=True)
BlueSpray = gateway.jvm.com.SchoonerTurtles
# Create the projector object from the GoogleMaps projector object
TheProjector=BlueSpray.SRS.STProjectorGoogleMaps()
# Project a geographic coordinate (WGS 84) to GoogleMaps
Lat=40.0
Lon=-120.0
Values=TheProjector.ProjectFromGeographic(Lon,Lat)
# Get the result and project it back to geographic
Easting=Values[0]
Northing=Values[1]
Values=TheProjector.ProjectToGeographic(Easting,Northing)
# Print the result
Lon=Values[0]
Lat=Values[1]
print("Original Lat,Lon= "+format(Lat)+", "+format(Lon))
print("Projected Easting, Northing= "+format(Easting)+", "+format(Northing))
print("Back-projected Lat,Lon= "+format(Lat)+", "+format(Lon))
GeometriesBlueSpray includes the OpenSource library from VividSolutions which works with simple geometric objects including Points, Polygons, and LineStrings (polylines). Rendering Geometries to Raster Files
importPackage(Packages.ST.Project);
importPackage(Packages.ST.Scene);
importPackage(Packages.ST.Raster);
importPackage(Packages.ST.File);
importPackage(Packages.ST.Vector);
var TheLayer=new LayerGeometry();
FileManager.LoadFromFile("E:/GIS_Data/US/states.shp",TheLayer,false);
Scene_1.AddChild(TheLayer);
var TheGeometry=TheLayer.GetGeometry(0);
var Result=GeometryUtil.SaveToRasterFile(TheGeometry,"C:/test.png",500,null);
Accessing a Database- var TheLayer=new ST.Layer.Vectors() - ST.SQL.Database.Query(Type,Source,Login,Password,Query,TheLayer) - ST.File.Manager.Save(FilePath,TheLayer) - TheScene.AddContent(TheLayer); - ST.File.Manager.Save(FilePath,Layer); - var ThePainter=ST.Painter.Directoins(); - var TheStyle=new ST.Style.Style(Color.RED,Color.WHITE,12); - ThePainter.SetStyle(TheStyle); - TheLayer.AddContent(ThePainter); Accessing Spatial Data in a DatabaseDatabases such as Micrsoft's SQL Server, PostgreSQL, and Oracle contain datatypes that contain vector spatial data. They also provide operators to work on this data. BlueSpray was created to work with this data and their functions. - var TheLayer=new ST.Layer.Vectors() - ST.SQL.Database.Query(Type,Source,Login,Password,Query,TheLayer) - ST.File.Manager.Save(FilePath,TheLayer) - TheScene.AddContent(TheLayer); - ST.File.Manager.Save(FilePath,Layer); - var ThePainter=ST.Painter.Directoins(); - var TheStyle=new ST.Style.Style(Color.RED,Color.WHITE,12); - ThePainter.SetStyle(TheStyle); - TheLayer.AddContent(ThePainter); Working with Rasters- var TheRaster=new ST.Raster.Raster(); - TheRaster=ST.Raster.Crop(TheRaster,100,100,200,200); - var TheCropper=new ST.Raster.Cropper(); - TheCropper.SetBackgroundColor(Color.BLACK); - TheRaster=TheCropper.Crop(TheRaster,100,100,200,200); - ST.File.Manager.Save(TheRaster,"C:/test.tif");
|
|||||||||